package com.review.Test.Future;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class futureTest {
	
	public static void main(String[] args) throws InterruptedException, ExecutionException {
		
		ExecutorService pool = Executors.newCachedThreadPool();
		Future<?> future = pool.submit(new Task(true, "任务开始", "任务结束"));
		Future<?> future1 = pool.submit(new Task(false, "任务开始1", "任务结束1"));
		
//		Task task = new Task();
//		task.setFlag(true);
//		task.setA("任务开始2");
//		task.setB("任务结束2");
//		Future<?> future2 = pool.submit(task);
		
		System.out.println("begin");
		Object object = future.get();
		Object object1 = future1.get();
//		Object object2 = future2.get();
		System.out.println(object);
		System.out.println(object1);
//		System.out.println(object2);
		System.out.println("end");
		pool.shutdown();
		
	}

}

class Task extends Thread{
	
	private boolean flag;
	private String a;
	private String b;
	

	public boolean isFlag() {
		return flag;
	}

	public void setFlag(boolean flag) {
		this.flag = flag;
	}

	public String getA() {
		return a;
	}

	public void setA(String a) {
		this.a = a;
	}

	public String getB() {
		return b;
	}

	public void setB(String b) {
		this.b = b;
	}

	public Task() {
		super();
	}

	public Task(boolean flag, String a, String b) {
		this.flag = flag;
		this.a = a;
		this.b = b;
	}

	public void run(){
		if (!flag) {
			return;
		}
		System.out.println(this.a);
		try {
			Thread.sleep(5000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		System.out.println(this.b);
	}
}